package com.ruoyi.customer.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.ruoyi.customer.domain.bo.TCustomerTaskBo;
import com.ruoyi.customer.domain.vo.TCustomerTaskVo;
import com.ruoyi.customer.service.ITCustomerTaskService;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户签单任务
 *
 * @author ruoyi
 * @date 2023-08-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/customerTask")
public class TCustomerTaskController extends BaseController {

    private final ITCustomerTaskService iTCustomerTaskService;

    /**
     * 查询客户签单任务列表
     */
    @SaCheckPermission("system:customerTask:list")
    @GetMapping("/list")
    public TableDataInfo<TCustomerTaskVo> list(TCustomerTaskBo bo, PageQuery pageQuery) {
        return iTCustomerTaskService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出客户签单任务列表
     */
    @SaCheckPermission("system:customerTask:export")
    @Log(title = "客户签单任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TCustomerTaskBo bo, HttpServletResponse response) {
        List<TCustomerTaskVo> list = iTCustomerTaskService.queryList(bo);
        ExcelUtil.exportExcel(list, "客户签单任务", TCustomerTaskVo.class, response);
    }

    /**
     * 获取客户签单任务详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:customerTask:query")
    @GetMapping("/{id}")
    public R<TCustomerTaskVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iTCustomerTaskService.queryById(id));
    }

    /**
     * 新增客户签单任务
     */
    @SaCheckPermission("system:customerTask:add")
    @Log(title = "客户签单任务", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TCustomerTaskBo bo) {
        return toAjax(iTCustomerTaskService.insertByBo(bo));
    }

    /**
     * 修改客户签单任务
     */
    @SaCheckPermission("system:customerTask:edit")
    @Log(title = "客户签单任务", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TCustomerTaskBo bo) {
        return toAjax(iTCustomerTaskService.updateByBo(bo));
    }

    /**
     * 删除客户签单任务
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:customerTask:remove")
    @Log(title = "客户签单任务", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iTCustomerTaskService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
